/*
 *  test2.cpp
 *  gmit
 *
 *  Created by DONG Li on 4/11/10.
 *  Copyright 2010 LASG/IAP. All rights reserved.
 *
 */


#include <iostream>

#include "mesh.h"
#include "meshmanager.h"

using namespace std;

int main(void)
{
    MeshManager<NoVar, double, double> meshMgr;
    
    meshMgr.setMeshType(MeshC);
    meshMgr.setMeshStructure(Structured);
    meshMgr.setMeshForm(Uniform);
    meshMgr.setNumDim(2);
    meshMgr.setNumCell(0, 2);
    meshMgr.setNumCell(1, 2);
    meshMgr.setBndX(0, 0.0, 1.0);
    meshMgr.setBndX(1, 0.0, 1.0);
    meshMgr.setBndType(0, 0, Periodic);
    meshMgr.setBndType(0, 1, Periodic);
    meshMgr.setBndType(1, 0, Periodic);
    meshMgr.setBndType(1, 1, Periodic);
    
    // set internal vertex grid cells
    for (int i = 1; i <= meshMgr.getNumCell(0); ++i) {
        for (int j = 1; j <= meshMgr.getNumCell(1); ++j) {
            vector<double> x(2);
            vector<Grid<NoVar> > vertices(4);
            int* vertexConn = new int[8];
            vertexConn[0] = 0;
            vertexConn[1] = 1;
            vertexConn[2] = 1;
            vertexConn[3] = 2;
            vertexConn[4] = 2;
            vertexConn[5] = 3;
            vertexConn[6] = 3;
            vertexConn[7] = 0;
            // down-left vertex
            x[0] = (i-1)*meshMgr.getDx(0);
            x[1] = (j-1)*meshMgr.getDx(1);
            vertices[0].setLocation(x);
            // down-right vertex
            x[0] = i*meshMgr.getDx(0);
            x[1] = (j-1)*meshMgr.getDx(1);
            vertices[1].setLocation(x);
            // up-right vertex
            x[0] = i*meshMgr.getDx(0);
            x[1] = j*meshMgr.getDx(1);
            vertices[2].setLocation(x);
            // up-left vertex
            x[0] = (i-1)*meshMgr.getDx(0);
            x[1] = j*meshMgr.getDx(1);
            vertices[3].setLocation(x);
            meshMgr.createVertexGridCell(Quadrilateral, vertices, vertexConn);
        }
    }
    
    // set boundary cells
    
    // operation test
    vector<double> x(2);
    x[0] = 0.3;
    x[1] = 0.6;
    cout << "cell index where (" << x[0] << "," << x[1] << ") is: ";
    cout << meshMgr.queryLocation(x) << endl;
    x[0] = 1.1;
    x[1] = 0.5;
    cout << "(" << x[0] << "," << x[1] << ") -> ";
    meshMgr.checkBoundary(x);
    cout << "(" << x[0] << "," << x[1] << ")" << endl;
    
    meshMgr.writeMeshFile();
}